package cn.com.chengmandian.bike.controller;


import cn.com.chengmandian.agent.utils.AuthUtil;
import cn.com.chengmandian.bike.dto.FaultAdviceAddForm;
import cn.com.chengmandian.bike.dto.FaultAdviceDto;
import cn.com.chengmandian.bike.log.ActionLog;
import cn.com.chengmandian.bike.model.vo.FaultAdviceVo;
import cn.com.chengmandian.bike.service.IEbFaultAdviceService;
import cn.com.chengmandian.core.db.pojo.PageData;
import cn.com.chengmandian.core.web.pojo.AgentInfo;
import cn.com.chengmandian.core.web.pojo.AgentUser;
import cn.com.chengmandian.core.web.pojo.AjaxResult;
import cn.com.chengmandian.core.web.utils.LocalMapUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.Assert;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 电单车运营-意见反馈 前端控制器
 * </p>
 *
 * @author AutoGenerator
 * @since 2021-12-23
 */
@Api(tags = "意见反馈相关接口")
@RestController
@RequestMapping("/fault/advice")
public class EbFaultAdviceController {
    @Autowired
    private IEbFaultAdviceService faultAdviceService;

    @ApiOperation("意见反馈-分页查询列表")
    @GetMapping(value = "/page",name = "意见反馈-分页查询列表")
    public AjaxResult<PageData<FaultAdviceVo>> getPage(
            FaultAdviceDto dto) {
        dto.setMemberId(AuthUtil.getAgentUser().getId());
        IPage<FaultAdviceVo> page = faultAdviceService.getPage(dto);
        return AjaxResult.success(PageData.build(page));
    }

    @ApiOperation("详情")
    @GetMapping("/detail/{id}")
    public AjaxResult<FaultAdviceVo> detail(@PathVariable("id") Integer id){
        return AjaxResult.success(faultAdviceService.detail(id));
    }

    @ApiOperation("提交意见反馈")
    @PostMapping("/add")
    @ActionLog(name="提交意见反馈",description = "'参数：' + #faultAdviceForm")
    public AjaxResult add(@RequestBody FaultAdviceAddForm faultAdviceForm) {
        AgentInfo agentInfo = LocalMapUtil.getAgentInfo();
        Assert.notNull(agentInfo.getAreaId(), "缺少运营区ID");
        Assert.notNull(faultAdviceForm.getType(), "请选择问题反馈类型");
        faultAdviceForm.setAreaId(agentInfo.getAreaId());
        AgentUser agentUser = AuthUtil.getAgentUser();
        faultAdviceService.addAdvice(faultAdviceForm, agentUser);
        return AjaxResult.success("提交成功，感谢您的反馈");
    }
}
